package com.gopay.bis.spdb.expay.operation;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.spdb.expay.SpdbMessageExPay;
import com.gopay.common.exception.GopayException;
import com.gopay.common.util.HttpTransport;
import com.gopay.remote.bank.ICertHelper;
/**
 * 浦发快捷查询接口
 * @author wjq
 *
 */
public class SpdbExPayQuery {
	/** 验签实现类 */
	private ICertHelper spdbExPayCertHelper; 
	/** HTTP实现类 */
	private HttpTransport httpTransport;
	private SpdbExPayBuildMessage spdbExPayBuildMessage;
	private SpdbExPayQueryParseMessage spdbExPayQueryParseMessage;
	/**
	 * 订单查询地址
	 */

	public Object query(SpdbMessageExPay message) throws GopayException {
		try {
			String signMsg = (String) this.spdbExPayCertHelper.sign(message);
			message.setSignMessage(signMsg);
			// 构建xml
			String buildMsg = spdbExPayBuildMessage.buildSignMessage(message);
			BankLogUtils.printExPayQueryReqLog(message, buildMsg);
			httpTransport.setUrl(message.getQueryUrl());
			httpTransport.setSendEncoding("GBK");
			Object obj = (Object) this.httpTransport.submit(buildMsg.getBytes()); // 发送银行
			message = spdbExPayQueryParseMessage.parseSpdbMessageExPay(obj);// 解析银行返回参数
			BankLogUtils.printExPayQueryResLog(message, ToStringBuilder.reflectionToString(message));
			return message;
		} catch (Exception e) {
			BankLogUtils.printExPayQueryExceptionLog(message, e);
			throw new GopayException(ProcCodeConstants.PROC_CODE_100E6037);
		}
	}

	public ICertHelper getSpdbExPayCertHelper() {
		return spdbExPayCertHelper;
	}

	public void setSpdbExPayCertHelper(ICertHelper spdbExPayCertHelper) {
		this.spdbExPayCertHelper = spdbExPayCertHelper;
	}

	public SpdbExPayBuildMessage getSpdbExPayBuildMessage() {
		return spdbExPayBuildMessage;
	}

	

	public void setHttpTransport(HttpTransport httpTransport) {
		this.httpTransport = httpTransport;
	}
	public void setSpdbExPayBuildMessage(SpdbExPayBuildMessage spdbExPayBuildMessage) {
		this.spdbExPayBuildMessage = spdbExPayBuildMessage;
	}

	public SpdbExPayQueryParseMessage getSpdbExPayQueryParseMessage() {
		return spdbExPayQueryParseMessage;
	}

	public void setSpdbExPayQueryParseMessage(SpdbExPayQueryParseMessage spdbExPayQueryParseMessage) {
		this.spdbExPayQueryParseMessage = spdbExPayQueryParseMessage;
	}
	

}
